* Use data from all studies
set more off
cd "${dropbox}/good guys/paper/data_code"

use gbc_s2, clear
append using gbc_s3
append using gbc_s4


drop if treatment==4
bysort id: egen type=mean(Type)
gen red=type==1 if treatment==2

egen mean_b=rowmean(b*)
lab var mean_b "Mean cond. contrib"


tempfile reg
gen ii=_n
preserve

keep if treatment==2
keep if !mi(b0)
keep ii b*

reshape long b, i(ii) j(others)
replace others=5*(others-6)

*Karens foretrukne def
*replace others=5*(others)


su b others

statsby, by(ii) clear: reg b others
rename _b_others pr_conditional
rename _b_cons pr_generous
save `reg'
restore

merge m:1 ii using `reg'





su pr_conditional if type==1, mean
	local cond_red=`r(mean)'
su pr_conditional if type==2, mean
	local cond_blue=`r(mean)'
su pr_generous if type==1, mean
	local gen_red=`r(mean)'
su pr_generous if type==2, mean
	local gen_blue=`r(mean)'



local barw 0.4 /// width of bars

cap drop gener_grp
*gen gener_grp=floor(pr_generous/5)+1

gen gener_grp=floor(pr_generous/6)+1
replace gener_grp=0 if pr_generous==0


keep if !mi(pr_gen)
preserve
collapse (count) id, by(gener_grp red)

su id if red
ret li
loca n_red=r(sum)

su id if !red
ret li
local n_blue=r(sum)


reshape wide id, i(gener_grp) j(red)
su

gen frac_blue=100*id0 /`n_blue'
gen frac_red=100*id1 /`n_red'	

gen g_below=gener_grp-.5*`barw'
gen g_above=gener_grp+.5*`barw'

local xlab 0 "0" 1 "1-9"
forvalues l=2/10 {
	local xlab `xlab' `l' "`=10*(`l'-1)'-`=10*`l'-1'"
	}
local xlab `xlab' 11 "100"

tw bar frac_blue g_below, barw(`barw') col(blue) ///
	|| bar frac_red g_above, barw(`barw') col(red) ///
	xlab(`xlab', angle(45)) legend(off) ///
	xtitle("Average level (% of endowment)") ytitle("Percent of subjects")
	
	